package com.gjy.sb2.controller;

import com.gjy.sb2.annotation.Decrypt;
import com.gjy.sb2.annotation.Encrypt;
import com.gjy.sb2.domain.AcceptInput;
import com.gjy.sb2.domain.AjaxResult;
import com.gjy.sb2.domain.StudentInfo;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * 接口安全测试接口
 *
 * @author gjy
 * @version 1.0
 * @since 2025-07-07 09:59:49
 */
@RestController
@RequestMapping("/safety")
public class SafetyController {

    @Decrypt
    @Encrypt
    @PostMapping(value = "/testAjax1")
    public AjaxResult testAjax1(@RequestBody AcceptInput<StudentInfo> body) {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setCode(0);
        ajaxResult.setMsg("success");
        ajaxResult.setData(body.getRequest());
        return ajaxResult;
    }

    @GetMapping(value = "/testGet", produces = "application/json;charset=UTF-8")
    public Map<String, Object> testGet(@RequestParam(value = "p", required = false) String p,
                                       @RequestParam(value = "ab", required = false) int ab,
                                       @RequestParam(value = "x", required = false) int x) {
        Map<String, Object> retMap = new HashMap<>();
        retMap.put("code", 0);
        retMap.put("message", "success");
        retMap.put("param1", p);
        retMap.put("param2", ab);
        retMap.put("param3", x);
        return retMap;
    }

    @PostMapping(value = "/testPostFromdata", produces = "application/json;charset=UTF-8", consumes = "application/x-www-form-urlencoded;charset=UTF-8")
    public Map<String, Object> testPostFromdata(@RequestParam(value = "p", required = false) String p,
                                                @RequestParam(value = "ab", required = false) int ab,
                                                @RequestParam(value = "x", required = false) int x) {
        Map<String, Object> retMap = new HashMap<>();
        retMap.put("code", 0);
        retMap.put("message", "success");
        retMap.put("param1", p);
        retMap.put("param2", ab);
        retMap.put("param3", x);
        return retMap;
    }

    @PostMapping(value = "/testPostBody", produces = "application/json;charset=UTF-8")
    public Map<String, Object> testPostBody(@RequestBody Map<String, Object> body) {
        Map<String, Object> retMap = new HashMap<>();
        retMap.put("code", 0);
        retMap.put("message", "success");
        retMap.put("body", body);
        return retMap;
    }

}
